home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr18 / chessclk.zip / CHESSCLK.HPP < prev    next >
C/C++ Source or Header  |  1995-04-15  |  3KB  |  168 lines

  1. // Chess clock header file
  2. // M\Cooper, 3425 Chestnut Ridge Rd., Grantsville, MD 21536-9801
  3. /***************************************************************************/
  4.  
  5. extern "C" two_tone(),
  6.        blatt(),
  7.     beep1(),
  8.     beep2();
  9.  
  10. #define PLAY 1
  11. #define GAME_OVER 1
  12. #define QUIT 2    
  13. #define ESC 27
  14. #define MAXLEN 4
  15. #define BUFSIZE 12
  16. #define BLK_TIME 460
  17. #define NAME_POS 530
  18. #define Y_TIMEPOS 300
  19. #define POS_OFFSET 158
  20. #define POS1_OFFSET 130
  21. #define COLORS 15
  22. #define PATTERNS 11
  23. #define RADIUS 50
  24. #define X_C 315
  25. #define Y_C 225
  26. #define MOVES_X 316
  27. #define MOVES_Y 440
  28.  
  29. typedef enum { FALSE, TRUE } BOOLEAN;
  30. enum FLAG { OFF, ON };
  31. enum Player { WHITE_, BLACK_ };
  32.  
  33. char *player[] = { "White", "Black" };
  34.  
  35. void graphics_setup( int ),
  36.      exit__();
  37.  
  38.  
  39.  
  40. class CountdownTimer
  41.    {
  42.    protected:
  43.       int hours,
  44.       minutes,
  45.       moves,
  46.       warning,
  47.       text_color;
  48.       char line_clear [ BUFSIZE ];
  49.      Player p,
  50.            pp;
  51.       FLAG running_flag,
  52.        visual_ticking_flag,
  53.        time_warning_flag;
  54.       time_t seconds,
  55.          total_seconds,
  56.          start_t,
  57.          end_t,
  58.          startn_t,
  59.          interval_t,
  60.          running_t;
  61.    public:
  62.       CountdownTimer()
  63.       {
  64.        hours = 2; minutes = moves = 0; seconds = 0L;
  65.        total_seconds = hours * 3600 + minutes * 60;
  66.        p = WHITE_;
  67.       }
  68.       CountdownTimer( int hrs, int min, time_t sec, Player pl )
  69.       {
  70.       hours = hrs; minutes = min; seconds = sec; moves = 0;
  71.       total_seconds = hours * 3600 + minutes * 60 + seconds;
  72.       p = pl;
  73.       }
  74.       CountdownTimer( int min, time_t sec, Player pl )
  75.       { 
  76.       sec += min * 60;
  77.       total_seconds = sec; 
  78.       hours = sec / 3600;
  79.       minutes = ( sec % 3600 ) / 60;
  80.       seconds = sec % 60;
  81.       moves = 0;
  82.       p = pl;
  83.       }
  84.       CountdownTimer( int hrs, int min, Player pl )
  85.      {
  86.      hours = hrs; minutes = min; seconds = 0L; moves = 0;
  87.      total_seconds = hours * 3600 + minutes * 60;
  88.      p = pl;
  89.      }
  90.       CountdownTimer( time_t sec, Player pl )
  91.       {
  92.       total_seconds = sec;
  93.       convert( sec );
  94.       p = pl;
  95.       moves = 0;
  96.       }
  97.       void convert( time_t sec )
  98.       { 
  99.       hours = sec / 3600;
  100.       sec %= 3600;
  101.       minutes = sec / 60;
  102.       seconds = sec % 60;
  103.       }
  104.  
  105.       void display_time()
  106.       {
  107.       char dbuff [ BUFSIZE ];
  108.  
  109.          sprintf( dbuff,  "%02d:%02d:%02ld", hours, minutes, seconds );
  110.  
  111.          erase_numbers();  // Wipe off old time.
  112.          
  113.          setcolor( text_color );
  114.          outtextxy( p * BLK_TIME, Y_TIMEPOS, dbuff );
  115.          sprintf( line_clear, dbuff );
  116.       }
  117.  
  118.       BOOLEAN timeout()
  119.      {
  120.      if( !hours )
  121.         if( !minutes )
  122.            if( !seconds )
  123.           {
  124.           two_tone();
  125.           return ( TRUE );
  126.           }
  127.      return ( FALSE );
  128.      }
  129.  
  130.       void exit_()
  131.       { 
  132.      char buff [20];
  133.  
  134.  
  135.       if( p )
  136.      sprintf( buff, "Black out of time." );
  137.       else
  138.      sprintf( buff, "White out of time." );
  139.  
  140.       setcolor( RED );
  141.       settextstyle( TRIPLEX_FONT, HORIZ_DIR, 1 );
  142.       outtextxy( 460, 440, buff );
  143.  
  144.       sprintf( buff, "PRESS A KEY" );
  145.       outtextxy( 460, 460, buff );
  146.  
  147.       getch();
  148.       closegraph();
  149.       exit ( GAME_OVER );
  150.       }
  151.  
  152.       void initialize_clock()
  153.       {
  154.       running_flag = OFF;  //Clock is running.
  155.       running_t = 0;
  156.       start_t = time( NULL );
  157.       }
  158.  
  159.       void clock_on(),
  160.        erase_numbers(),
  161.        display_moves(),
  162.         ShowFlag();
  163.  
  164.      friend void play();
  165.     
  166.     }; //end class defn.
  167.  
  168.